package com.sx.gongzhong.pest;

import com.sx.gongzhong.model.CommentBean;
import com.sx.gongzhong.model.HeadParamBean;
import com.sx.gongzhong.model.HelpBean;
import com.sx.gongzhong.model.ReplyUserBean;
import com.sx.gongzhong.net.BaseCallBack;
import com.sx.gongzhong.model.BasePageListBean;
import com.sx.gongzhong.net.HelpManager;
import com.sx.gongzhong.view.HelpDetailView;

import java.util.Map;

/**互帮互助 详情
 * Created by admin on 2018/1/13.
 */

public class HelpDetailPest {
    private HelpDetailView helpDetailView;

    public HelpDetailPest(HelpDetailView helpDetailView) {
        this.helpDetailView = helpDetailView;
    }
    //详情
    public void getHelpDetail(String adviceId) {
        Map<String,Object> map = HeadParamBean.getHead();
        map.put("helpId",adviceId);
        new HelpManager().getHelpDetail(map, new BaseCallBack<ReplyUserBean.BaseResult<HelpBean>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<HelpBean> response) {
                helpDetailView.getHelpDetailSuccess(response.data);
            }
            @Override
            public void onFailures(String message) {
                helpDetailView.showError("获取详情失败");
            }
        });
    }
    //大众回复列表
    public void getHelpCommentList(String helpId, int page, int pageSize) {
        Map<String,Object> map = HeadParamBean.getHead();
        map.put("dataId",helpId);
        map.put("page",page);
        map.put("rows",pageSize);
        new HelpManager().getHelpCommentList(map, new BaseCallBack<ReplyUserBean.BaseResult<BasePageListBean<CommentBean>>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<BasePageListBean<CommentBean>> response) {
                helpDetailView.getHelpCommentListSuccess(response.data.rows,response.data.total);
            }
            @Override
            public void onFailures(String message) {
                helpDetailView.showError(message);
            }
        });
    }
    //大众回复(添加)
    public void addComment(String helpId, String content) {
        Map<String,Object> map = HeadParamBean.getHead();
        map.put("dataId",helpId);
        map.put("content",content);
        new HelpManager().addHelpComment(map, new BaseCallBack<ReplyUserBean.BaseResult<CommentBean>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<CommentBean> response) {
                helpDetailView.addCommentSuccess(response.data);
            }
            @Override
            public void onFailures(String message) {
                helpDetailView.showError(message);
            }
        });
    }
    //点赞 (添加)
    public void addHelpPraise(String helpId) {
        Map<String,Object> map = HeadParamBean.getHead();
        map.put("helpId",helpId);
        new HelpManager().addHelpPraise(map, new BaseCallBack<ReplyUserBean.BaseResult<Integer>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Integer> response) {
                helpDetailView.addHelpPraiseSuccess(response.data);
            }
            @Override
            public void onFailures(String message) {
                helpDetailView.showError(message);
            }
        });
    }

    //关闭
    public void closeHelp(String helpId) {
        Map<String,Object> map = HeadParamBean.getHead();
        map.put("helpId",helpId);
        new HelpManager().closeHelp(map, new BaseCallBack<ReplyUserBean.BaseResult<Boolean>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Boolean> response) {
                helpDetailView.closeHelpSuccess(response.data);
            }
            @Override
            public void onFailures(String message) {
                helpDetailView.showError(message);
            }
        });
    }
    //删除
    public void deleteHelp(String helpId) {
        Map<String,Object> map = HeadParamBean.getHead();
        map.put("ids",helpId);
        new HelpManager().deleteHelp(map, new BaseCallBack<ReplyUserBean.BaseResult<Boolean>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Boolean> response) {
                helpDetailView.deleteHelpSuccess(response.data);
            }
            @Override
            public void onFailures(String message) {
                helpDetailView.showError(message);
            }
        });
    }
}
